<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.frame.platform.dept.DeptTreeJson"%>
<%@page import="com.frame.platform.dept.Wfdept"%>
<%@taglib uri="/WEB-INF/page-base.tld" prefix="w"%>

<%Wfdept root=(Wfdept)new DeptTreeJson().getRoot();
String treejson=request.getAttribute("OrgTree").toString();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML xmlns="http://www.w3.org/1999/xhtml">
  <head>
  	<%@ include file="/platform/style.jsp"%>
	<meta http-equiv="Content-Type" content="text/html; charset=gk2312" />
	<script type="text/javascript" src="<%=path %>/platform/message/imm/imm.js"></script>
	<script src='<%=path %>/platform/UI/js/ui.core.js' type='text/javascript'></script>
	<link href='<%=path %>/util/js/dtree/skin/ui.dynatree.css' rel='stylesheet' type='text/css'>
	<script src='<%=path %>/util/js/dtree/jquery.dynatree.js' type='text/javascript'></script>
	<style>
	.icon_sendinfo{background: url('<%=path %>/platform/UI/style/blue/images/imm.png') no-repeat;}
	.icon_lookuser{background: url('<%=path %>/platform/message/icon/page_user.gif') no-repeat;}
	</style>
	<script>
	$(function(){
		window.setTimeout(receiveImm,25000);
		$(".easyui-tree").tree({
			data: window.eval('[<%=treejson%>]'),
			onClick: function(node){
				$(this).tree('toggle', node.target);
			},
			onDblClick:function(node){
				if($(node).attr("id").indexOf("u_")!=-1){
					$("[name='userid']").val($(node).attr("id").replace("u_",""));
					$("[name='username']").val(node.text);
					imm_user_show();
				}
			},
			onContextMenu: function(e,node){
				e.preventDefault();
				if($(node).attr("id").indexOf("u_")!=-1){
					$("[name='userid']").val($(node).attr("id").replace("u_",""));
					$("[name='username']").val(node.text);
					$(this).tree('select',node.target);
					$('#mm').menu('show',{
						left: e.pageX,
						top: e.pageY
					});
				}
				
			}
		})
	})
	function receiveImm(){
		$w.doUrl(ctx+'/platform/message/imm/ImmPage@receiveImm.page',{},function(json){
			var div=$("#Imm_List_div");
			if(json.data){
				$(json.data).each(function(i){
					if(window.parent.lastId=="")if(i==0)window.parent.lastId=this.id+"";
					if(this.tag=='1' || this.tag=='3')
						html="<div class='imm_li'><div class='imm_titlebg'><span class='imm_title'>系统消息</span><span class='imm_time' style='padding-left:4px;'>"+this.immTime+"</span></div><div class='imm_content'>"+this.content+"</div></div>";
					else
						html="<div class='imm_li'><div class='imm_titlebg'><span class='imm_title'><a href='javascript:imm_show(\""+this.immFrom+"\",\""+this.formUser+"\");' class='imm_a'>"+this.formUser+"（"+this.formDept+"）</a></span><span class='imm_time' style='padding-left:4px;'>"+this.immTime+"</span></div><div class='imm_content'>"+this.content+"</div></div>";
					div.append(html);
				});
				var scrollTop = div[0].scrollHeight;
            	div.scrollTop(scrollTop);
			}
			window.setTimeout(receiveImm,25000);
		})
	}
	function imm_show(uid,uname){
		window.parent.$w.openWin({id:'mainImmshow_'+uid,url:ctx+'/platform/message/imm/ImmPage@show.page?userId='+uid,iframe:true,w:570,h:460,title:uname+' 消息会话',collapsible:false,maximizable:false,icon:'icon_imm'})
		//window.parent.close_immBox();
	}
	function imm_user_show(){
		imm_show($("[name='userid']").val(),$("[name='username']").val());
	}
	function showhistory(){
		window.parent.$w.addTab({title:'消息记录',iconUrl:ctx+'/platform/UI/style/blue/images/script.png',href:ctx+'/platform/message/imm/ImmPage@showHistoryImm.page',fresh:true});
	}
	function openProjectInfo(pid){
		window.parent.openProjectInfo(pid);
	}
	function openWeeklydeal(id){
		window.parent.$w.addTab({id:'problemShowtab',title:'问题跟踪',href:ctx+'/promanage/ProjectTrackPage@openproblemShow.page?id='+id+"&showdeal=true"})
		window.parent.close_immBox();
	}
	function opengongs(state){
		var s="";
		if(state)s=state;
		window.parent.$w.addTab({id:'gongsShowtab',title:'工时查询',href:ctx+'/promanage/diaoy/GongsPage.page?state='+s})
		window.parent.close_immBox();
	}
	</script>
<body class="easyui-layout">
  	<div data-options="region:'center',border:true">
	  	<div class="easyui-layout" fit="true">
	  		<div data-options="region:'center',border:false" id="Imm_List_div">
		  		<w:iterate id="info" bind="immList">
		  			<div class="imm_li">
		  			<div class="imm_titlebg"><span class='imm_title'>
		  			<w:switch>
		  				<w:case bind="#info.tag==1 || #info.tag==3">系统消息</w:case>
		  				<w:else><a href="javascript:imm_show('<w:write bind="#info.immFrom"/>','<w:write bind="#info.formUser"/>');" class="imm_a"><w:write bind="#info.formUser"/>（<w:write bind="#info.formDept"/>）</a></w:else>
		  			</w:switch>
		  			</span><span class='imm_time'><w:write bind="#info.immTime" format="MM-dd HH:mm"/></span>
		  			</div>
		  			<div class="imm_content"><w:define id="content" bind="#info.content" /><%=content %></div>
		  			</div>
		  		</w:iterate>
	  		</div>
			<div data-options="region:'south',split:false,border:false" style="height:32px" class="imm-buttonBar">
				<a href="#" class="easyui-linkbutton" iconCls="" onclick="showhistory()" data-options="iconUrl:'<%=path %>/platform/UI/style/blue/images/script.png'">消息记录</a>&nbsp;<a href="#" class="easyui-linkbutton" iconCls="icon_cancel" onclick="window.parent.$w.closeCurrWin()"> 关闭 </a>
			</div>
	  </div>
	</div>
	<div data-options="region:'east',split:true" style="width:180px" title="组织架构">
		<input name="userid" type="hidden"/>
		<input name="username" type="hidden"/>
  		<ul id="tt" class="easyui-tree"></ul>
	</div>
	<div id="mm" class="easyui-menu" style="width:120px;">  
        <div onclick="imm_user_show()" data-options="iconCls:'icon_sendinfo'">发送消息</div>  
        <div onclick="remove()" data-options="iconCls:'icon_lookuser'">查看资料</div>  
	</div>

</body>
</html>